<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
	<title>分类管理</title>
	 <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	<!--<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/demo.css">
	--><script type="text/javascript">
		$(function(){
			$('#sortList').datagrid({
				title:'分类列表',
				iconCls:'icon-ok',
				url:'${ctx}/info/core/info!data.action',
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[10,15,20,30],
				idField:'sortId',
				columns:[[
					{field:'sortCode',title:'分类编号',width:100},
					{field:'sortName',title:'分类名称',width:100},
					{field:'infoTableName',title:'表名称',width:100},
					{field:'objName',title:'对象名',width:100},
					{field:'sortStatus',title:'状态',width:100,
						formatter:function(value){
							if(value=="0"){
							    return "<font color='red'>未启用</font>";
							}else{
							    return "<font color='green'>已启用</font>";
							}
						}
					},
					{field:'sortId',title:'操作',width:100,
						formatter:function(value,rowData){
						    var str ="";
							if(rowData.sortStatus=="1"){
								var startUrl = "${ctx}/info/core/stop.action?id="+value;
							    str += "<a href='javascript:void(0);' onclick=\"executeTask('"+startUrl+"','"+rowData.sortName+"',1)\">停用</a>";
							} else {
								var startUrl = "${ctx}/info/core/publish.action?id="+value;
							    str += "<a href='javascript:void(0);' onclick=\"executeTask('"+startUrl+"','"+rowData.sortName+"',2)\">启用</a>";
							}
							return str;
						}
					}
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveSort();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteSort();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editSort();
					}
				},'-',{
					text:'数据列表',
					iconCls:'icon-edit',
					handler:function(){
						metadataList();
					}
				},'-',{
					text:'生成代码',
					iconCls:'icon-remove',
					handler:function(){
						createCode();
					}
				}]
			});
		});
		
		// 关闭添加、修改div
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		// 刷新列表
		function reload(){
			$('#sortList').datagrid('reload');
		}
		
		function executeTask(url,sortName,type){
			var title="您确定要启用:<font color=red>"+sortName+"</font> ？";
			if(1==type){
				title="您确定要关闭:<font color=red>"+sortName+"</font> ？<br/><br/>关闭同时<font color=red>将会删除所有数据！！</font><br/><br/>！！！！！正式环境下勿使用！！！！！";
			}
			$.messager.confirm('确认',title,function(r){
				if(r){
				$.ajax({
					type: "post",
					url: url,
					dataType: "json",
					success: function(data){
						var result = data;
						if(result.flag=='T'){
							$.messager.alert('结果', '操作成功', 'info',function(){
							    $('#sortList').datagrid('reload');
							});	
						} else{
							$.messager.alert('结果', result.msg, 'error');	
						}
					}
				});
				}
			});
		}
		
		// 增加应用系统
		function saveSort(){
			$('#saveFrame').html('');			
			var url = '${ctx}/info/core/add.action';				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		// 修改应用系统
		function editSort(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/info/core/add.action?sortId='+node.sortId;
				$('#saveFrame').attr("title",node.sortName);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		// 判断是否选中了需要操作的数据[修改、删除]
		function getSelected(){
			var selected = $('#sortList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		function createCode(){
			$('#createFrame').html('');
			var url = '${ctx}/info/core/createCode.action';
			$('#createFrame').attr("title","生成代码");
		    $('#createFrame').attr("src",url);
			$('#createDiv').window('open');
		}
		
		// 删除
		function deleteSort(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.sortName+'</font> ？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/info/core/del.action?id="+node.sortId,
							success: function(data, textStatus){
								var result = jQuery.parseJSON(data);
		    					if(result.flag=='T'){
									$.messager.alert('结果', result.msg, 'info',function(){	
									var rowIndex = $('#sortList').datagrid('getRowIndex',node);								
									$('#sortList').datagrid('deleteRow', rowIndex);	
									});
		    					}else{
		    						$.messager.alert('结果', result.msg, 'error');	
		    					}
		    				}
						});
		          	}
		       });		             		
		    }	
		}	
		
		// 模块列表
		function metadataList(){
			var node = getSelected();
		    if(node){		    
				$('#unitListFrame').html('');
				var url = '${ctx}/info/metadata/list.action?sortId='+node.sortId;											
				$('#unitListFrame').attr("src",url);
			    $('#unitListWin').window('open');
			    $('#unitListWin').window('setTitle','[<font color=red>'+node.sortName+'</font>]数据元素管理');
		    }		
		}

	</script>
</head>
<body>
	<!-- 应用列表 -->
	<table id="sortList"></table>
	
	<!-- 增加、修改窗口 -->
	<div id="saveDiv" class="easyui-window" title="添加数据分类" style="padding:5px;width: 500px;height:250px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 	<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="auto" frameborder="0" ></iframe>
    </div>
    
    <!-- 模块列表窗口 -->
	<div id="unitListWin" class="easyui-window" title="数据元素管理" style="padding:2px;width:880px;height:510px;top: 50px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 	<iframe frameborder="0"  id="unitListFrame" height="100%" width="100%" scrolling="auto" frameborder="0" ></iframe>
	</div>

   <div id="createDiv" class="easyui-window" title="生成代码" style="padding:5px;width: 880px; height:510px;"
    	iconCls="icon-search" closed="true" maximizable="true" collapsible="false">
   	 	<iframe frameborder="0"  id="createFrame" height="100%" width="100%" scrolling="auto" frameborder="0" ></iframe>
    </div>
</body>
</html>